<?php
require_once "my_profile_left_pane.php";

	require_once "includes/class/member_management.class.php";
	require_once('AmazonAPI/.config.inc.php');
	require_once('AmazonAPI/CBUI/CBUIRecipientTokenPipeline.php');
	
	if($_SESSION['user_id_sess']=="") {
		echo "<script type='text/javascript'> window.location='index.php?signin&url=profile'; </script>";
	}
	$userId = $_SESSION['user_id_sess'];	
	$usrObj = new member_management;
	$rand = rand(100000, 10000000);
	
	if(isset($_REQUEST['signature']) && !empty($_REQUEST['signature'])) {
		$signature = $_REQUEST['signature'];
		$refundTokenID = $_REQUEST['refundTokenID'];
		$signatureVersion = $_REQUEST['signatureVersion'];
		$signatureMethod = $_REQUEST['signatureMethod'];
		$certificateUrl = $_REQUEST['certificateUrl'];
		$tokenID = $_REQUEST['tokenID'];
		$callerReference = $_REQUEST['callerReference'];
		$sqlUpdUsr = "UPDATE tbl_users SET signature='".$signature."',
					refundTokenID='".$refundTokenID."',
					signatureVersion='".$signatureVersion."',
					signatureMethod='".$signatureMethod."',					
					certificateUrl='".$certificateUrl."',
					tokenID='".$tokenID."',
					callerReference='".$callerReference."' WHERE user_id='$userId'";
		$rstUpdUsr = mysql_query($sqlUpdUsr) or die(mysql_error());
		if($rstUpdUsr) { 
			$msg = "Your tokenID is successfully set.";
		}else{
			$msg = "Your tokenID is not set please try again!";
		}
	}
	
	
	
	if(isset($_POST['editProfile'])) {
	
	$arr_user_info = mysql_fetch_array(mysql_query("SELECT * FROM tbl_users WHERE user_id='$userId'"));
	if(($_REQUEST['secretAnswer']==$arr_user_info['username']) || ($_REQUEST['secretAnswer']==$arr_user_info['password']))
	{
	   $msg ='<font color="#FF0000"><strong>Security answer should not be username or password.</strong></font>';
	}
	else
	{
		$businessName		=	$_REQUEST['businessName'];
		$physicalLocation	=	$_REQUEST['physicalLocation'];
		$bus_id			=	$_REQUEST['bus_id'];
	    $other_business_type    =   addslashes($_REQUEST['other_business_type']);
		$businessDescription	=	$_REQUEST['businessDescription'];
		$special_in             =   addslashes($_REQUEST['special_in']);
		$address1		=	$_REQUEST['address1'];
		$state			=	$_REQUEST['state'];
		$city			=	$_REQUEST['city'];
		$zip			=	$_REQUEST['zip'];
		$phoneNumber1		=	$_REQUEST['phoneNumber1'];
		$phoneNumber2		=	$_REQUEST['phoneNumber2'];
		$phoneNumber3		=	$_REQUEST['phoneNumber3'];
		$extension1		    =	$_REQUEST['extension1'];
		$phoneNumber4		=	$_REQUEST['phoneNumber4'];
		$phoneNumber5		=	$_REQUEST['phoneNumber5'];
		$phoneNumber6		=	$_REQUEST['phoneNumber6'];
		$extension2		=	$_REQUEST['extension2'];
		$phone1=$phoneNumber1."-".$phoneNumber2."-".$phoneNumber3;
		if(!empty($extension1)) {
			$phone1.="-".$extension1;
		}
		$phone2=$phoneNumber4."-".$phoneNumber5."-".$phoneNumber6;
		if(!empty($extension2)) {
			$phone2.="-".$extension2;
		}
		$email			=	$_REQUEST['email'];
		$first_name		=	$_REQUEST['first_name'];
		$last_name		=	$_REQUEST['last_name'];
		$businessEmail		=	$_REQUEST['businessEmail'];
		$secretQuestion		=	$_REQUEST['secretQuestion'];
		$secretAnswer		=	$_REQUEST['secretAnswer'];
		
		
		
		//image upload code commeted as there is no iamge upload option in below form
		/*$profileImage = $_FILES['profile_image']['name'];
		if($profileImage!="") {
			$pathInfo = pathinfo($profileImage);
			$ftype = strtolower($pathInfo['extension']);
			if($ftype=="jpeg" || $ftype=="jpg" || $ftype=="gif") {
			
				$pathSource = "users/source/".$rand.$userId.".".$ftype;
				$pathSample = "users/sample/".$rand.$userId.".".$ftype;
				$pathThumb = "users/thumb/".$rand.$userId.".".$ftype;
				
				if(move_uploaded_file($_FILES['profile_image']['tmp_name'],$pathSource)) {
					//get and delete old images
					$userImages = $usrObj->getUserImage($userId);
					print_r($userImages);
					
					if($userImages[0]!="") {
						unlink($userImages[0]);
					} 
					if($userImages[1]!="") {
						 unlink($userImages[1]);
					}
					
					
					imageResize($pathSource, $pathThumb, $pathSample, $ftype);
					
					$sqlUpd = "UPDATE tbl_users SET profile_sample='$pathSample', profile_thumb='$pathThumb' 
							   where user_id='$userId'";
					$rstUpd = mysql_query($sqlUpd);
					if($rstUpd) {
						unlink($pathSource);					
					}		   
				}
			}
		}*/
		
		//change state id to state name
		/*if(is_numeric($state)) {
			$state = getStateName($state);
		} 
		//change city id to city name
		if(is_numeric($city)) {
			$city = getCityName($city);
		}*/
		
		
		$sqlUpdUsr = "UPDATE tbl_users SET
			business_name='".$businessName."',
			physicalLocation='".$physicalLocation."',
			bus_id='".$bus_id."',
            other_business_type='".$other_business_type."',
			businessDescription='".$businessDescription."',
			special_in='".$special_in."',
			address_line_1='".$address1."',
			city='".$city."',
			state='".$state."',
			zip='".$zip."',
			phone_number_1='".$phone1."',
			phone_number_2='".$phone2."',
			email='".$email."',
			first_name='".$first_name."',
			last_name='".$last_name."',
			secret_question=".$secretQuestion.",
			secret_answer='".sanitize($secretAnswer)."',
			businessEmail='".$businessEmail."'
			WHERE user_id='$userId'";
		$rstUpdUsr = mysql_query($sqlUpdUsr) or die(mysql_error());
		if($rstUpdUsr) { 
			//header("location:setAmazonToken.php");
			/*if(($prev_pm != $payment_method) || empty($tokenID)){
				$pipeline = new Amazon_FPS_CBUIRecipientTokenPipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);
				if($_SESSION['user_type_sess']!='5')
				{
					$pipeline->setMandatoryParameters("swapen".rand(),  
						H_ROOT."index.php?profile=1", "0", "5.1", "True");
				}
				else
				{
					$pipeline->setMandatoryParameters("swapen".rand(),  
						H_ROOT."index.php?profile=1", "0", "1.1", "True");
				}
				//optional parameters
				$pipeline->addParameter("paymentMethod", "CC");
				$re_URL = $pipeline->getUrl();
				header("location:".$re_URL);
			}else{
				$msg = "Your profile updated successfully.";
			}*/
			if($_REQUEST['u_type']=='3' || $_REQUEST['u_type']=='5')
			{
				$subject="Crucial Business Info Updated";
				$message="Dear ".$_REQUEST['fname']." ".$_REQUEST['lname'].",<br><br>
	".$_REQUEST['username']." has updated his business profile info and we need to re-evaluate him. <br><br>Thank you<br><br>Swapen Team";
				$full_name=$_REQUEST['fname']." ".$_REQUEST['lname'];
				$headers = "From: ".$full_name."<".$_REQUEST['email']."> \r\n";
				$headers .= 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
				mail("contactus@Swapen.com",$subject, $message, $headers);
			}
			$msg = "<font color='#006600'>Your profile updated successfully.</font>";
		
		}
		else { $msg=""; }					
		
		/* if($usrObj->updateUserInfo($userId,$firstName,$lastName,$address1,$address2,$city,$state,$country,$zip,$phone,$email,$age,$aboutMe)) {
			$msg = "Your profile updated successfully.";
		}
		else {
			$msg="";
		}		 */
		
		}
		
	}
	
	if(isset($_GET['new_request']) && ($_GET['new_request'] == 1)){
		$pipeline = new Amazon_FPS_CBUIRecipientTokenPipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);

		$pipeline->setMandatoryParameters("swapen".rand(),  
				H_ROOT."index.php?profile", "0", "5.1", "True");
		
		//optional parameters
		$pipeline->addParameter("paymentMethod", $payment_method);
		$re_URL = $pipeline->getUrl();
		header("location:".$re_URL);
	}
	
	$userInfo = $usrObj->getMemberById($userId);
	$phoneArr = explode("-",$userInfo['phone_number_1']);
	$phoneArr1 = explode("-",$userInfo['phone_number_2']);
	//print_r($userInfo);
	if($_REQUEST['profile']=='1' && $msg=="")
	{
		$msg = "Your token updated successfully.";
	}	
?>
<script src="<?php echo $base_url?>js/jquery.custom_radio_checkbox.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
	$(".radio").dgStyle();
	$(".checkbox").dgStyle();
});
</script>
<div class="releftbox_out">
	<div class="releftbox_top">&nbsp;</div>
	<div class="releftbox_repeat">
		<h1 style="float:left; width:100%; text-align:center; margin-top:-10px;">My Account Info</h1>
		<span style="float:left; width:96%; text-align:right; padding:0px5px 5px 0px;"><a href="javascript:void(0);">FAQ</a></span>
		<div id="messageAreaTop" style="margin:10px 0px 10px 20px; float:left;"><?php if(isset($msg)) echo "<b>".$msg."</b>"; ?></div>
		<form enctype="multipart/form-data" name="frmEditProfile" method="post" action="" onSubmit="return validateForm();">
		<input type="hidden" name="fname" value="<?php echo $userInfo['first_name']?>" />
		<input type="hidden" name="lname" value="<?php echo $userInfo['last_name']?>" />
		<input type="hidden" name="username" value="<?php echo $userInfo['username']?>" />
		<input type="hidden" name="u_type" value="<?php echo $userInfo['user_type']?>" />
<?php if($userInfo['user_type']==3 || $userInfo['user_type']==4 || $userInfo['user_type']==5) { ?>
		<div class="blue_box">
			<div class="bluebar_left"></div>
			<div class="bluebar_center"><span>Business Info</span></div>
			<div class="bluebar_right"></div>
		</div>
		
		<div class="blue_box">
			<div class="form_field_box">
				<label for="businessName" id="lblBusinessName">Business Name:</label>
				<span>
				
				<input type="text" value="<?php echo $userInfo['business_name']; ?>" name="businessName" id="businessName" class="inputbg" style="width:110px;" />
				
				</span>
			</div>
		<?php if($userInfo['user_type']==3) { ?>
			<div class="form_field_box">
				<label for="physicalLocation" id="lblphysicalLocation">Physical Location Name:</label>
				<span>
				
				<input type="text" name="physicalLocation" id="physicalLocation" class="inputbg" style="width:110px;" value="<?php echo $userInfo['physicalLocation']; ?>" />
				
				</span>
			</div>
			<?php } ?>
		</div>
		<?php if($userInfo['user_type']!=5) { ?>
		<div class="blue_box">
			<div class="form_field_box">
				<label for="btype" id="lblBusinessType">Business Type:</label>
				<span>
					<select name="bus_id" id="bus_id"  style="width:185px; height:28px;" class="inputbg" onchange="business_other(this.value);">
						<option value="">Select Business Type...</option> 
						<?php			   
						$sqlSelCountry="SELECT * FROM tbl_businesstype";
						$rstSelCountry=mysql_query($sqlSelCountry);
						while($rowSelCountry=mysql_fetch_array($rstSelCountry))
						{
							$bus_id=$rowSelCountry['bus_id'];
							$business_type=$rowSelCountry['business_type'];
							echo "<option value='$bus_id'>$business_type</option>";
						}
						?>
					</select>
					<script>$('#bus_id').val(<?php echo $userInfo['bus_id']?>);</script>
				</span>
			</div>
			<div class="form_field_box">
				<label for="businessDescription" id="lblbusinessDescription">Business Description:</label>
				<span>
					<select name="businessDescription" id="businessDescription" style="width:120px; height:28px;" class="inputbg">
						<option value="retail">Retail</option>
						<option value="manufacture">Manufacture</option>
						<option value="services">Services</option>
					</select>
					<script>$('#businessDescription').val('<?php echo $userInfo['businessDescription']?>');</script>
				</span>
			</div>
		</div>
		
		<?php if($userInfo['other_business_type']!="") { ?>
			<div class="blue_box" id="other_business" style="display:">
				<div class="form_field_box_full">
					<label for="other_business_type" id="lblother_business_type">Please Specify:</label>
					<span>
					
					<input type="text" name="other_business_type" id="other_business_type" value="<?php echo stripslashes($userInfo['other_business_type'])?>" class="inputbg" />
					
					</span>
				</div>
			</div>
			<?php } ?>
			
		<?php } ?>
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="address1" id="lblAddress1">Business Address:</label>
				<span>
				
				<input type="text" name="address1" id="address1" class="inputbg" value="<?php echo $userInfo['address_line_1'].$userInfo['address_line_2']; ?>" />
				
				</span>
			</div>
		</div>
		
<?php if($userInfo['user_type']==5) { ?>
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="address1" id="lblAddress1">Specialize:</label>
				<span>
				
				<input type="text" name="special_in" id="special_in" class="inputbg" value="<?php echo $userInfo['special_in']; ?>" />
				
				</span>
			</div>
		</div>
		<?php } ?>

		<div class="blue_box">
			<div class="form_field_box">
				<label for="country" id="lblCountry">Country:</label>
				<span>
					<select name="country" id="country" style="width:145px; height:28px;" class="inputbg">
						<option value="">Select country...</option> 
						<?php			   
						$sqlSelCountry="SELECT * FROM tbl_country where code='US'";
						$rstSelCountry=mysql_query($sqlSelCountry);
						while($rowSelCountry=mysql_fetch_array($rstSelCountry))
						{
							$cty_id=$rowSelCountry['country_id'];
							$cty_name=$rowSelCountry['country_name'];
							echo "<option value='$cty_id' selected='selected'>$cty_name</option>";
						}
						?>
					</select>
				</span>
			</div>
			<div class="form_field_box">
				<label for="state "id="lblState">State:</label>
				<span>
					<input type="text" class="inputbg" name="state" id="state1" value="<?php echo $userInfo['state']; ?>" style="width:110px;" />
				</span>
			</div>
		</div>
		<div class="blue_box">
			<div class="form_field_box">
				<label for="city" id="lblCity">City:</label>
				<span>
					<input type="text" class="inputbg" name="city" id="city1" value="<?php echo $userInfo['city']; ?>" style="width:110px;" />
				</span>
			</div>
			<div class="form_field_box">
				<label for="zip" id="lblZip">Zip Code:</label>
				<span>
				
				<input type="text" name="zip" id="zip"  class="inputbg" value="<?php echo $userInfo['zip']; ?>" style="width:110px;"/>
				
				</span>
			</div>
		</div>
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="phoneNumber1" id="lblPhoneNumberPrimary">Telephone:</label>
				<span style="width:200px;">
					<input type="text" onkeydown='return onlyint(event,1);' name="phoneNumber1" id="phoneNumber1" maxlength="4" style="width:25px;" value="<?php echo $phoneArr[0]; ?>" class="inputbg" /><font style="padding:10px 0px 0px 0px;"> - </font>
					<input type="text" onkeydown='return onlyint(event,1);' name="phoneNumber2" id="phoneNumber2" maxlength="4" style="width:25px;" value="<?php echo $phoneArr[1]; ?>" class="inputbg" /><font style="padding:10px 0px 0px 0px;"> - </font>
					<input type="text" onkeydown='return onlyint(event,1);' name="phoneNumber3" id="phoneNumber3" maxlength="6"  style="width:25px;" value="<?php echo $phoneArr[2]; ?>"  class="inputbg" /> <font style="padding:10px 0px 0px 0px;">Ext :</font>
					<input type="text" onkeydown='return onlyint(event,1);' name="extension1" id="extension1" maxlength="20"  style="width:25px;" value="<?php echo $phoneArr[3]; ?>"  class="inputbg" />
				</span>
				<span style="float:left; color:red; width:100px; display:none;" id="digit_err1">Digits Only</span>
			</div>	
		</div>
		<div class="blue_box">
			<div class="form_field_box">
				<label for="email" id="lblEmail">Email:</label>
				<span><input type="text" name="email" id="email" value="<?php echo $userInfo['email']; ?>" class="inputbg" style="width:170px;" /></span>
			</div>
			<div class="form_field_box">
				&nbsp;
			</div>
		</div>
<?php } ?>		
		
		<div class="blue_box">
			<div class="bluebar_left"></div>
			<div class="bluebar_center"><span>Personal Info</span></div>
			<div class="bluebar_right"></div>
		</div>
		
		<div class="blue_box">
			<div class="form_field_box">
				<label for="firstName" id="lblFirstName">First Name:</label>
				<span>
				
				<input type="text" name="first_name" id="first_name" value="<?php echo $userInfo['first_name']; ?>" class="inputbg" style="width:110px;" />
				
				</span>
			</div>
			<div class="form_field_box">
				<label for="lastName" id="lblLastName">Last Name:</label>
				<span>
				
				<input type="text" name="last_name" id="last_name" value="<?php echo $userInfo['last_name']; ?>" class="inputbg" style="width:110px;" />
				
				</span>
			</div>
		</div>
		<div id="samename" style="display: none;">&nbsp;&nbsp;First Name and Last Name cannot be the same. </div>
		
		<?php if($userInfo['user_type']==1 || $userInfo['user_type']==2) { ?>
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="phoneNumber4" id="lblPhoneNumberSecondary">Telephone:</label>
				<span style="width:200px;">
					
<input type="text" onkeydown='return onlyint(event,1);' name="phoneNumber1" id="phoneNumber1" maxlength="4" style="width:25px;" value="<?php echo $phoneArr[0]; ?>" class="inputbg" /><font style="padding:10px 0px 0px 0px;"> - </font>
					<input type="text" onkeydown='return onlyint(event,1);' name="phoneNumber2" id="phoneNumber2" maxlength="4" style="width:25px;" value="<?php echo $phoneArr[1]; ?>" class="inputbg" /><font style="padding:10px 0px 0px 0px;"> - </font>
					<input type="text" onkeydown='return onlyint(event,1);' name="phoneNumber3" id="phoneNumber3" maxlength="6"  style="width:25px;" value="<?php echo $phoneArr[2]; ?>"  class="inputbg" /> <font style="padding:10px 0px 0px 0px;">Ext :</font>
					<input type="text" onkeydown='return onlyint(event,1);' name="extension1" id="extension1" maxlength="20"  style="width:25px;" value="<?php echo $phoneArr[3]; ?>"  class="inputbg" />
					</span>
				<span style="float:left; color:red; width:100px; display:none;" id="digit_err2">Digits Only</span>
			</div>	
		</div>
		<div class="blue_box">
			<div class="form_field_box">
				<label for="email" id="lblEmail">Email:</label>
				<span><input type="text" name="email" id="email" value="<?php echo $userInfo['email']; ?>" class="inputbg" style="width:170px;" /></span>
			</div>
			<div class="form_field_box">
				&nbsp;
			</div>
		</div>
		<div class="blue_box">
			<div class="form_field_box">
				<label for="email" id="lblEmail">Re-enter email:</label>
				<span><input type="text" name="email" id="email" value="<?php echo $userInfo['email']; ?>" class="inputbg" style="width:170px;" /></span>
			</div>
			<div class="form_field_box">
				&nbsp;
			</div>
		</div>
		<?php } else { ?>
		<div class="blue_box">
			<div class="form_field_box_full">
				<label for="phoneNumber4" id="lblPhoneNumberSecondary">Telephone:</label>
				<span style="width:200px;">
					
					<input type="text" onkeydown='return onlyint(event,2);' name="phoneNumber4" id="phoneNumber4" maxlength="4" style="width:25px;" value="<?php echo $phoneArr1[0]; ?>" class="inputbg" /><font style=" padding:10px 0px 0px 0px;"> - </font>
					
					<input type="text" onkeydown='return onlyint(event,2);' name="phoneNumber5" id="phoneNumber5" maxlength="4" style="width:25px;" value="<?php echo $phoneArr1[1]; ?>" class="inputbg" /><font style="padding:10px 0px 0px 0px;"> - </font>
					
					<input type="text" onkeydown='return onlyint(event,2);' name="phoneNumber6" id="phoneNumber6" maxlength="6"  style="width:25px;" value="<?php echo $phoneArr1[2]; ?>" class="inputbg" /><font style="padding:10px 0px 0px 0px;"> Ext : </font>
					
					<input type="text" onkeydown='return onlyint(event,2);' name="extension2" id="extension2" maxlength="20"  style="width:25px;" value="<?php echo $phoneArr1[3]; ?>" class="inputbg" />
				</span>
				<span style="float:left; color:red; width:100px; display:none;" id="digit_err2">Digits Only</span>
			</div>	
		</div>
		<div class="blue_box">
			<div class="form_field_box">
				<label for="businessEmail" id="lblbusinessEmail">Email:</label>
				<span>
				
				<input type="text" name="businessEmail" value="<?php echo $userInfo['businessEmail']; ?>" id="businessEmail" class="inputbg" style="width:170px;" />
				
				</span>
			</div>
			<div class="form_field_box">
				<label for="businessEmailAgain" id="lblbusinessEmailAgain">Re-enter email:</label>
				<span>
					
					<input type="text" name="businessEmailAgain" value="<?php echo $userInfo['businessEmail']; ?>" id="businessEmailAgain"  class="inputbg" style="width:170px;" />
					
				</span>
			</div>
		</div>
		<?php } ?>
		<div class="blue_box">
			<div class="form_field_box">
            <label for="secretQuestion" id="lblsecretQuestion">Pick a secret question:</label>
				<span>
				<select name="secretQuestion" id="secretQuestion" style="width:300px; height:28px;" class="inputbg">
							<option value="">Select a secret question</option>
							<?php
							$sqlSelQuestion = "select * from tbl_questions";
							$rstSelQuestion = mysql_query($sqlSelQuestion) or die(mysql_error());
							while($rowSelQuestion = mysql_fetch_array($rstSelQuestion))
							{ ?>
							<option value="<?php echo $rowSelQuestion['question_id'] ?>" <?php if($rowSelQuestion['question_id']==$userInfo['secret_question']) { echo 'selected'; }?>><?php echo $rowSelQuestion['question'] ?></option>
							<?php } ?>
						</select>
				</span>
			</div></div>
			
			
		<div class="blue_box">
			<div class="form_field_box">
				<label for="secretAnswer" id="lblsecretAnswer">Your seceret answer:</label>
				<span>
					
					<input type="text" name="secretAnswer" id="secretAnswer" value="<?php echo stripslashes($userInfo['secret_answer'])?>" class="inputbg" style="width:300px;" />
					
				</span>
			</div>
		</div>
	
		<div class="blue_box">
			&nbsp;
		</div>
		<div class="blue_box">
			<div class="form_field_box_full">
				<div class="checkbox"><input name="accept" id="accept" type="checkbox" /> </div> &nbsp;&nbsp;
				<label style="text-align:left;">I agree that:</label>
				<div id="lblAgreement" style="display:none; color:#FF0000; font-weight:bold">Acceptance of  agreement is must to register. </div>
			</div>
			<br /><br /><br />
			<ul>
				<li>I accept the <a href="" tabindex="1">User Agreement</a> and <a href="index.php?policy" target="_blank">Privacy Policy</a>.</li>
				<li>I may receive communications from swapen.</li>
				<li>I'm at least 18 years old.</li>
			</ul>
		</div>
		<div class="blue_box" style="text-align:center;">
			<input type="submit" name="editProfile" id="editProfile" value="UPDATE" class="sbmt_btn" />
		</div>
		<div id="errMsg" style="margin:10px 0px 10px 20px; float:left;"></div>
		</form>
	</div>
		
	<div class="releftbox_bot">&nbsp;</div>
</div>		
<script>
function onlyint(event,a) {
	
	var charCode = event.keyCode || event.which;
	if(event.shiftKey && charCode == 9)
	{return true}
	else  if (event.shiftKey)
	{	$('#digit_err'+a).show().fadeOut("slow"); return false;	}
	else if  (((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode == 8) || (event.keyCode == 9) || (event.keyCode == 46)) )
	{ return true; } else { $('#digit_err'+a).show().fadeOut("slow"); return false; }
}
function validateForm()
{
	var flag=0;
	if($('#businessName').val()=='')
	{
		flag=flag+1;
		$('#lblBusinessName').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblBusinessName').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#physicalLocation').val()=='')
	{
		flag=flag+1;
		$('#lblphysicalLocation').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblphysicalLocation').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#bus_id').val()=='')
	{
		flag=flag+1;
		$('#lblBusinessType').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblBusinessType').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#address1').val()=='')
	{
		flag=flag+1;
		$('#lblAddress1').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblAddress1').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#state1').val()=='')
	{
		flag=flag+1; 
		$('#lblState').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblState').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#city1').val()=='')
	{
		flag=flag+1;
		$('#lblCity').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblCity').css({'font-weight':'normal','color':'#666666'});
	}
	if($('#zip').val()=='')
	{
		flag=flag+1;
		$('#lblZip').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblZip').css({'font-weight':'normal','color':'#666666'});
	}
	if($('#phoneNumber1').val()=='' && $('#phoneNumber2').val()=='' && $('#phoneNumber3').val()=='' && $('#extension1').val()=='')
	{
		flag=flag+1;
		$('#lblPhoneNumberPrimary').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblPhoneNumberPrimary').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#email').val()=='')
	{
		flag=flag+1;
		$('#lblEmail').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblEmail').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#first_name').val()=='')
	{
		flag=flag+1;
		$('#lblFirstName').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblFirstName').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#last_name').val()=='')
	{
		flag=flag+1;
		$('#lblLastName').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblLastName').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#phoneNumber4').val()=='' && $('#phoneNumber5').val()=='' && $('#phoneNumber6').val()=='' && $('#extension2').val()=='')
	{
		flag=flag+1;
		$('#lblPhoneNumberSecondary').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblPhoneNumberSecondary').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#businessEmail').val()=='')
	{
		flag=flag+1;
		$('#lblbusinessEmail').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblbusinessEmail').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#businessEmailAgain').val()=='')
	{
		flag=flag+1;
		$('#lblbusinessEmailAgain').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblbusinessEmailAgain').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#businessEmail').val()!=$('#businessEmailAgain').val())
	{
		flag=flag+1;
		$('#lblbusinessEmail').css({'font-weight':'bold','color':'#FF0000'});
		$('#lblbusinessEmailAgain').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblbusinessEmail').css({'font-weight':'normal','color':'#666666'});
		$('#lblbusinessEmailAgain').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#secretQuestion').val()=='')
	{
		flag=flag+1;
		$('#lblsecretQuestion').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblsecretQuestion').css({'font-weight':'normal','color':'#666666'});
	}
	
	if($('#secretAnswer').val()=='')
	{
		flag=flag+1;
		$('#lblsecretAnswer').css({'font-weight':'bold','color':'#FF0000'});
	}
	else {
		$('#lblsecretAnswer').css({'font-weight':'normal','color':'#666666'});
	}
	
	
	if($("#accept").is(":checked")==false)
	{
		flag=flag+1;
		alert('You have to agree our conditions before submiting your data.');
	}
	
	if(flag>0)
	{
		$('#errMsg').html("<font color='#FF0000'><b>We need some additional information from you. Enter valid information in red color highlighted fields and try again.</b></font>");
		return false;
	}
	else
	{
		$('#errMsg').html('');
		alert('Due to major changes to your business we will be contacting you to within 3 days to re-evaluate and confirm your business. If you have any questions contact us at support@swapen.com \n\nAlso please send us as an email with the subject "Major Business Updates Need Re-Evaluation". Please state the fields that were updated and what they were previously. Also include the user profile link.');
		return true;
	}
}
</script>		

<script language="javascript" type="text/javascript">
function business_other(bus)
{
	if(bus==59)
	{
	  document.getElementById('other_business').style.display='';
	}
	else
	{
	  document.getElementById('other_business').style.display='none';
	}
}
</script>